'''
装饰器
'''
import time


def fac(n):
    start = time.time()
    sum1 = 1
    for num in range(1, n + 1):
        sum1 *= num
    print('{}的阶乘：{}'.format(n, sum1))
    end = time.time()
    print('执行时间：', end - start)


# 方法二
def add_time(fn):
    start = time.time()
    fn()
    end = time.time()
    print('执行时间：%fs' % (end - start))


def add_time2(fn, *args, **kwargs):
    start = time.time()
    fn(*args, **kwargs)
    end = time.time()
    print('执行时间：%fs' % (end - start))


def func1():
    print('============')
    print('+++++++++++++')


def func2():
    print('hello world')
    print('hello python')


add_time(func1)

print('--------------------------')


def add_time3(fn):
    def test(*args, **kwargs):
        s = time.time()
        fn(*args, **kwargs)
        e = time.time()
        print('执行时间：%fs' % (e - s))

    return test


@add_time3
def func5():
    print('hello')


func5()

print('---------练习---------------------')


def hex1(fn):
    def test(*args, **kwargs):
        num = fn(*args, **kwargs)
        if isinstance(num,int):  # 判断num是否是整型
            return hex(num)

    return test


@hex1
def sum1(x, y):
    return x + y


print(sum1(60, 2))
